package day09.daemon;

import java.util.concurrent.TimeUnit;

/**
 * @Auther: sky
 * @Date: 2019/3/12 22:43
 * @Description:守护线程，finallly并不一定会执行
 */
public class DaemonDemo {

    /**
     * 守护线程时，不能依靠f in al ly 块中的内容来确保执行关闭或清理资源
     * 的逻辑。
     * @param args
     */
    public static void main(String[] args) {
        Thread thread = new Thread(new DaemonRunner(), "DaemonRunner");
        //setDaemon设置为后台线程
        thread.setDaemon(true);
        thread.start();
    }
    static class DaemonRunner implements Runnable {
        @Override
        public void run() {
            try {
                TimeUnit.MILLISECONDS.toSeconds(10);
            } finally {
                System.out.println("DaemonThread finally run.");
            }
        }
    }
}
